package com.bnq.control.desktop.xmlview;

import java.util.HashMap;
import java.util.Map;

import android.view.View;
import android.view.View.OnClickListener;

import com.bnq.control.R;


public class KeyboardCtrlView extends XmlView {

	static int[] key_id = { R.id.btn_id_pack_up, R.id.btn_id_ctrl,
			R.id.btn_id_shift, R.id.btn_id_alt, R.id.btn_id_win,
			R.id.btn_id_more_one };

	public KeyboardCtrlView(View view) {
		super(view);
	}

	@Override
	protected void onInitClickView(View rootView, OnClickListener l) {
		super.onInitClickView(rootView, l);
		View v;
		for (int i = 0; i < key_id.length; i++) {
			v = rootView.findViewById(key_id[i]);
			v.setOnClickListener(l);
		}
	}

	@Override
	public void onClick(View v) {
		int vId = v.getId();
		if (R.id.btn_id_shift == vId || R.id.btn_id_ctrl == vId
				|| R.id.btn_id_alt == vId || R.id.btn_id_win == vId
				|| R.id.btn_id_more_one == vId) {
			boolean selected = v.isSelected();
			v.setSelected(!selected);
		}
		super.onClick(v);
	}

	public final static Map<Integer, String> mKey = new HashMap<Integer, String>() {
		/**
		 *
		 */
		private static final long serialVersionUID = 1L;

		{
			put(R.id.btn_id_shift, "SHIFT");
			put(R.id.btn_id_ctrl, "CTRL");
			put(R.id.btn_id_alt, "ALT");
			put(R.id.btn_id_win, "LWIN");
		}
	};

	public boolean isCtrlDown() {
		View view = getView().findViewById(R.id.btn_id_ctrl);
		return view.isSelected();
	}

	public boolean isShiftDown() {
		View view = getView().findViewById(R.id.btn_id_shift);
		return view.isSelected();
	}

	public boolean isAltDown() {
		View view = getView().findViewById(R.id.btn_id_alt);
		return view.isSelected();
	}

	public boolean isWinDown() {
		View view = getView().findViewById(R.id.btn_id_win);
		return view.isSelected();
	}

	public boolean isMoreDown() {
		View view = getView().findViewById(R.id.btn_id_more_one);
		return view.isSelected();
	}

	public boolean isFunDown() {
		return isCtrlDown() || isShiftDown() || isAltDown() || isWinDown();
	}

	public void clearAllDown() {
		View rootView = getView();
		View v;
		for (int i = 0; i < key_id.length; i++) {
			v = rootView.findViewById(key_id[i]);
			v.setSelected(false);
		}
	}

}
